﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;

namespace SailHero.Soft.ESB.Client
{
    /// <summary>
    /// This class is a sample custom wire protocol to use as wire protocol in SailHero.Soft.ESB framework.
    /// </summary>
    public class MyProtocol 
    {

        public byte[] SerializeMessage(Message message)
        {

            Message msg = new Message();
            msg.Content = Encoding.ASCII.GetBytes(((Message)message).Text);
            msg.Size = msg.Content.Length;//当需要分包处理时再行考虑，此时只是一个单一的数据包
            //msg.CRC = 0xffff;
            byte[] _byte = msg.ToBytes();
            return _byte;
        }

        public Message DeserializeMessage(byte[] bytes)
        {
            //Decode UTF8 encoded text and create a TextMessage object
            Message msg = Message.FromBytes(bytes);
            if (msg.Head == "##")
            {
                return msg;
            }
            return null;

        }

    }
}
